#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
    int maxProfit(vector<int>& prices) {
		if (prices.size() < 2)
			return 0;
		int tmax=0;
		int last=prices[prices.size()-1];
		for(int i=prices.size()-2;i>=0;--i)
		{
			if (last > prices[i])
			{
				tmax = max(tmax, last - prices[i]);
			}
			else
				last = prices[i];
		}
		return tmax;
    }
};